package com.general.framework.example.filterRepeatArrayListItem;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListRemoveTest {

    public static void main(String[] args) {
        List<User> users = new ArrayList<User>();
        users.add(new User("liu1",24));
        users.add(new User("liu2",24));
        users.add(new User("liu3",24));
        users.add(new User("liu4",24));
        // Java集合删除指定元素 以下方法解决 ConcurrentModificationException 异常
        // https://blog.51cto.com/u_16213700/7385747
        Iterator<User> iterator = users.iterator();
        while(iterator.hasNext()) {
            User user = iterator.next();
            if(user.getName().equals("liu2")) {
                iterator.remove();
            }
            System.out.println(user);
        }
        System.out.println(users); 
    }
}